package com.koi.common.utils.i18n;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

/**
 * @author ･ᴗ･
 * @description [I18nUtil国际化工具]
 */
@Component
public class I18nUtil {

    public static MessageSource messageSource;

    public I18nUtil(MessageSource messageSource) {
        // spring的bean注入
        I18nUtil.messageSource = messageSource;
    }

    /**
     * @description [获取国际化翻译值]
     */
    public static String get(String msgKey) {
        return messageSource.getMessage(msgKey, null, LocaleContextHolder.getLocale());
    }

    /**
     * @description [获取国际化翻译值（包括占位符）]
     */
    public static String get(String msgKey, Object... args) {
        return messageSource.getMessage(msgKey, args, LocaleContextHolder.getLocale());
    }

}
